
// 获取浏览器信息
function getBrowserInfo() {
  var UA = window.navigator.userAgent.toLowerCase();
  var regTag = /android|iphone|windows phone|ipad/i;
  var sDevice = UA.match(regTag);
  var isClient = /youyi/.test(UA); //是否UYI的客户端
  var isWxBrowser = /MicroMessenger/i.test(UA);
  var info = {
    device: sDevice && sDevice.length > 0 ? "mobile" : "pc",
    os: sDevice && sDevice.length > 0 ? sDevice[0] : "pc",
    isClient: isClient,
    isWxBrowser: isWxBrowser
  };
  window.browserInfo = info;
  return info;
}

//IOS-webView-javascript-briged
//调用APP方法
var jsBridge = false;
var browserInfo = getBrowserInfo(); 
function setupWebViewJavascriptBridge(callback) {
  if (browserInfo.os === "iphone"){
    if (window.WebViewJavascriptBridge) { return callback(WebViewJavascriptBridge); }
    if (window.WVJBCallbacks) { return window.WVJBCallbacks.push(callback); }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement('iframe');
    WVJBIframe.style.display = 'none';
    WVJBIframe.src = 'wvjbscheme://__BRIDGE_LOADED__';
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function() { document.documentElement.removeChild(WVJBIframe) }, 0)
  }else if (browserInfo.os === "android"){
  
  	    if (window.WebViewJavascriptBridge) {
                callback(WebViewJavascriptBridge)
            		
           } else {            	
                document.addEventListener(
                    'WebViewJavascriptBridgeReady'
                    , function() {
                        callback(WebViewJavascriptBridge)
                       
                    },
                    false
                );
              
            }

  	
  }
}
//调用h5

setupWebViewJavascriptBridge(function(bridge) {
  /* Initialize your app here */
  jsBridge = bridge;  
  if (browserInfo.os === "android"){
  	jsBridge.init(function(message, responseCallback) {
          
 	 });
  }
  
  jsBridge.registerHandler('openCurrentwork', function(data, responseCallback) {
        /*document.getElementById("show").innerHTML = "buuton js" + data;
        responseCallback("button js callback");*/         
       openCurrentwork();
    })  
})

// ***** 调用 android app 方法传递3个参数 并 打开视频页面   ****//
function openAppUploadImage(obj) {
    
 	if(browserInfo.os === "android"){
 		
 		//window.android.uploadPhoto(obj);
   		
         window.WebViewJavascriptBridge.callHandler(
            'uploadPhoto'
            //传递3个参数到 android app
            , obj
         );
 	}else if (browserInfo.os === "iphone") {
		jsBridge.callHandler('uploadPhoto', obj);
	}
}

/*setupWebViewJavascriptBridge(function(bridge) {
  //Initialize your app here 
    jsBridge = bridge;

    jsBridge.registerHandler('javascriptHandler', function(data, responseCallback) {
        document.getElementById("show").innerHTML = "buuton js" + data;
        responseCallback("button js callback");
    })  
})*/


//初始化生成页面
function openCurrentwork(){
  if(!$(".myphotoalbum").is(":hidden")){
  	$(".myphotoalbum").hide();
  }
	//workid=work_id;
	opentype=2;
	//作品页面初始化接口 并且生成作品
	initializationwork();
	
}

//调用app传图
function openAppUpload(obj){
	openAppUploadImage(obj);
	
}
